package 网络编程.TCP协议;

import org.apache.commons.io.input.ReaderInputStream;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class 接收数据 {
    public static void main(String[] args) throws IOException {
        //TCP协议接收数据

        //1.创建
        ServerSocket ss=new ServerSocket(10000);

        //2.监听客户端的连接
        Socket socket = ss.accept();

        //3.从连接通道中获取输入流读取数据
        //创建转换流的对象,将字 节转换为字符
        InputStreamReader isr = new InputStreamReader(socket.getInputStream());
        BufferedReader br = new BufferedReader(isr);
        int b;
        while ((b=br.read())!=-1){
            System.out.print((char) b);
        }

        //4.释放资源
        br.close();
        ss.close();

    }
}
